#include <string.h>
#include <iostream>
#include <string>

using namespace std;
using std::string;

int main()
{
    string str;
    cout << "str:" << str << endl;
    cout << "is str empty:" << str.empty()<< endl;
    cout << "str'size ：" << str.size()<< endl;

    //string(size_type count ,char ch) 生成一个string字符串
    //对象，该对象包含count个ch字符
    //创建一个str1有5个a字符
    string str1(5,'a');
    //错误要转化为C风格字符串
    // cout << strlen(str);
    cout << strlen(str1.c_str()) << endl;;
    cout << "str1:" << str1 << endl;
    cout << "is str1 empty:" << str1.empty()<< endl;
    cout << "str1'size ：" << str1.size()<< endl;
    
    //通过c风格字符串创建字符串
    const char * a = "hello";
    string str2(a);
    cout << "str2:" << str2 << endl;
    
    //string(const char * rhs, size_type count);
    //通过rhs的前count个字符构造一个string对象
    string str3("ssssss",2);
    string str4(a,3);
    cout << "str3:" << str3 << endl;
    cout << "str4:" << str4 << endl;

    //使用拷贝构造函数创建字符串
    string str5(str2);
    string str6 = str3;
    cout << "str5:" << str5 << endl;
    cout << "str6:" << str6 << endl;
    
    //已区间内的字符创建字符串
    auto it2 = str1.begin();
    auto it3 = str1.end();
    string str7(it2,it3);
    cout << "str7:" << str7 << endl;

    //使用字符串拼接来创建字符串
    string str8 = str2 + str3;
    string str9 = str2 + ",wwww";
    cout << "str8:" << str8 << endl;
    cout << "str9:" << str9 << endl;

    return 0;
}